<template>
    <van-sticky>
        <van-nav-bar title="列表" left-arrow @click-left="onClickLeft" />
    </van-sticky>

    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <van-card v-for="item in 20 " num="2" price="2.00" desc="描述信息" title="商品标题"
                thumb="https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg" @click="pushlian(item.goods_id)"/>

        </van-list>
    </van-pull-refresh>

</template>

<script setup>
import axios from "axios";
import { ref } from "vue";
const onClickLeft = () => history.back();
import { useRouter, useRoute } from 'vue-router'
const router = useRouter();
const route = useRoute();

const goodsList = ref([]);
axios.get("https://api-hmugo-web.itheima.net/api/public/v1/goods/search", {
    params: {
        cid: route.query.cid
    }
}).then(res => {
    goodsList.value = res.data.message
})

const pushlian=(goods_id)=>{
    router.push({
        path:"/Detail",
        query:goods_id,
        id:5
    })
}


const list = ref([]);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);

const onLoad = () => {
    setTimeout(() => {
        if (refreshing.value) {
            list.value = [];
            refreshing.value = false;
        }

        for (let i = 0; i < 10; i++) {
            list.value.push(list.value.length + 1);
        }
        loading.value = false;

        if (list.value.length >= 40) {
            finished.value = true;
        }
    }, 100);
};

const onRefresh = () => {
    // 清空列表数据
    finished.value = false;

    // 重新加载数据
    // 将 loading 设置为 true，表示处于加载状态
    loading.value = true;
    onLoad();
};
</script>

<style lang="scss" scoped></style>